<style scoped>
    .layui-row {
        overflow: hidden;
    }
    .select-item {
        width: 34.333333%;
        float: right;
    }
    .layui-row:after, .layui-row:before {

    }
    .layui-form >>> .layui-form-select{
        z-index: inherit;
    }
</style>

<template>
    <div class="organization">

        <form class="layui-form " >
            <div  class="layui-col-lg4 select-item" style="text-align: right;width: auto" >
                <div class="layui-inline" style="width: 200px">
                    <select      v-model="batchGuid"  name="batchGuid"  id="batchGuid" placeholder="请选择批次"    class="layui-input layui-unselect"    >
                        <option value="" >请选择批次</option>
                        <option v-for="item in batchs" :value="item.guid" >{{item.name}}</option>
                    </select>
                </div>
                <button type="button" class="layui-btn sou" @click="search">搜索</button>
            </div>

        </form>
        <table class="layui-table layui-form">

            <thead>
            <tr>
                <th>种植户名称</th>
                <th>种植户手机号</th>
                <th>应付重量</th>
                <th>应付金额</th>
                <th>应付车数</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <tr class="id9" v-for="(val, index) in payinfos" :key="val.guid">
                <td>{{val.realName}}</td>
                <td>{{val.telphone}}</td>
                <td>{{val.unpaidWeight}}</td>
                <td>{{val.unpaidSettlement}}</td>
                <td>{{val.unpaidCount}}</td>
                <td><a href="javascript:;" @click="toAction(val.plantorid)">查看</a> </td>
            </tr>
            </tbody>
        </table>

        <Pagination :cur="currentPage" :all="totalPage" :callback="turnPage" ></Pagination>
        <div style="height: 200px"></div>

    </div>
</template>

<script>
    import Pagination from '../common/Pagination.vue'
    export default {
        name: 'paymentApplication',
        components: {Pagination},
        props: ['id'],
        data () {
            return {
                guid : this.id,
                organizations: [],
                currentPage: 1,
                totalPage: 0,
                searchName: '',
                batchs:[],
                batchGuid:'',
                payinfos:[]
            }
        },
        updated: function () {
            layui.form.render('select');
            layui.form.render();
        },
        mounted() {
            let that = this;

            layui.use(['form'], function () {
                var form = layui.form,
                    layer = layui.layer;
                that.getBaseInfo();
            });

        },
        methods: {
            search: function() {
                this.getPageData('search');
            },
            turnPage: function(data){
                this.currentPage = data;
                this.getPageData();
            },
            getPageData: function(type = '') {
                let that = this;
                let loader = layui.layer.load();

                let postData = {};

                if (type != 'search') {
                    postData.page = that.currentPage;
                }
                postData.batchid = $('#batchGuid').val()
                that.batchGuid = postData.batchid;
                var optionAll = that.selectPermisAll(that.batchGuid,that.batchs,"无授权批次!");
                if(optionAll){
                    postData.pbguids = optionAll;
                }
                $.ajax({
                    url: '/harvest/Print!getPaymentApplication.action',
                    type: "post",
                    data: postData,
                    dataType: "json",
                    success: function(res) {

                        if (res != undefined && res.rows != undefined) {
                            //分页数据赋值
                            that.currentPage = res.indexPage;
                            that.totalPage = res.pageCount;
                            that.payinfos = res.rows;
                        } else {
                            that.alert("系统错误");
                        }
                    },
                    complete: function () {
                        layer.close(loader);
                    }
                });
            },
            toAction: function (id) {
                this.$parent.gid = id;
                this.$parent.switchPage('FreightorderPayList');
            },
            getBaseInfo: function (id) {
                this.$post('/harvest/Print!getBatchByUserPayment.action')
                    .then(response => {
                        let data = response.data;
                        if (data.msg == 'success') {
                            this.batchs = data.batchs;
                            this.getPageData();
                        } else {
                            this.toast('获取批次失败！');
                        }
                    })
            },
            /**
             * 查询权限内所有选项的数据
             * @param guid  选择框内选项
             * @param entitys 选择框内所有枚举值
             */
            selectPermisAll:function (guid,entitys,description){
                if(entitys.length == 0){
                    this.toast(description);
                    return false;
                }
                if( guid !=''){
                    return false;
                }
                var srguids = [];
                $.each(entitys, function (index, entity) {
                    srguids.push(entity.guid)
                });
                return srguids.toString();
                }
            },



    }
</script>
